//
//  OYRetweetView.swift
//  weiboCopycat
//
//  Created by Orange Yu on 2016/12/5.
//  Copyright © 2016年 Orange Yu. All rights reserved.
//

import UIKit


class OYHomeRetweetView: UIView {

    var bottomConstraint: Constraint?

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    var statusVM: OYStatusViewModel? {
        didSet {
            
            contentLabel.text = statusVM?.retweetContent
            
            bottomConstraint?.uninstall()
            if let picUrls = statusVM?.statusModel?.retweeted_status?.pic_urls,picUrls.count > 0 {
                // 有图片
                pictureView.isHidden = false
                pictureView.picUrls = picUrls
                self.snp_updateConstraints(closure: { (make) in
                    bottomConstraint = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusItemMargin).constraint
                })
            }else {
                // 没有图片
                pictureView.isHidden = true
                self.snp_updateConstraints(closure: { (make) in
                    bottomConstraint = make.bottom.equalTo(contentLabel.snp_bottom).offset(StatusItemMargin).constraint
                })
            }
        }
    }
    
     // MARK: -控件的懒加载

    /// 内容
    lazy var contentLabel:UILabel = {
        let label = UILabel(text: "来自星星的你", fontSize: 16, color: UIColor.black)
        label.numberOfLines = 0
        return label
    }()
    
    /// 图片
    lazy var pictureView: OYHomePictureView = {
        let pictureView = OYHomePictureView()
        return pictureView
    }()
    
    func setupUI()  {
        self.backgroundColor = UIColor(red: 0.95, green: 0.95, blue: 0.95, alpha: 1)
        addSubview(contentLabel)
        addSubview(pictureView)
    
        contentLabel.snp_makeConstraints { (make) in
            make.left.top.equalTo(self).offset(StatusItemMargin)
            make.right.equalTo(self).offset(-StatusItemMargin)
//            make.bottom.equalTo(self).offset(-StatusItemMargin)
        }
        
        pictureView.snp_makeConstraints { (make) in
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusItemMargin)
            make.left.equalTo(contentLabel)
//            make.size.equalTo(CGSize(width: 100, height: 100))
        }
        
        self.snp_makeConstraints { (make) in
             bottomConstraint = make.bottom.equalTo(pictureView).offset(StatusItemMargin).constraint
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
 

}
